package com.parking.mgr.useraccount.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.parking.mgr.common.annotion.BusinessLog;
import com.parking.mgr.common.pojo.page.PageResult;
import com.parking.mgr.common.pojo.response.Result;
import com.parking.mgr.useraccount.model.param.ParkingRecordInfoParam;
import com.parking.mgr.useraccount.model.vo.ParkingRecordInfoVO;
import com.parking.mgr.useraccount.service.ParkingRecordReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName ParkingRecordInfoController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/3/6
 */
@Slf4j
@Api(value = "停车备案信息审核", tags = {"停车备案信息审核"})
@RequestMapping("/api/parking/record/review")
@RestController
public class ParkingRecordReviewController {

    @Resource
    private ParkingRecordReviewService parkingRecordReviewService;

    @PostMapping("/review")
    @ApiOperation(value = "提交停车备案信息审核", notes = "提交停车备案信息审核", httpMethod = "POST")
    @BusinessLog(title = "提交停车备案信息审核")
    public Result<?> save(@ApiParam(name = "id", value = "id")
                              @RequestParam(name = "id", required = false) String id, HttpServletRequest request) {
        parkingRecordReviewService.review(id);
        return Result.success();
    }

    @PostMapping("/update/review")
    @ApiOperation(value = "修改停车备案信息审核状态", notes = "修改停车备案信息审核状态", httpMethod = "POST")
    @BusinessLog(title = "修改停车备案信息审核状态")
    public Result<?> save(@RequestBody ParkingRecordInfoParam parkingRecordInfoParam, HttpServletRequest request) {
        parkingRecordReviewService.updateReview(parkingRecordInfoParam);
        return Result.success();
    }

    @GetMapping("/detail")
    @ApiOperation(value = "停车备案详情",notes = "停车备案详情",httpMethod = "GET")
    public Result<?> detail(@ApiParam(name = "id", value = "id")
                                @RequestParam(name = "id", required = false) String id, HttpServletRequest request){

        return Result.success(parkingRecordReviewService.detail(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "停车备案审核列表",notes = "停车备案审核列表",httpMethod = "GET")
    public Result<?> listReview(ParkingRecordInfoParam parkingRecordInfoParam, HttpServletRequest request){
        IPage<ParkingRecordInfoVO> parkingRecordInfoVOIPage = parkingRecordReviewService.listReview(parkingRecordInfoParam, request);
        List<ParkingRecordInfoVO> parkingRecordInfoList = parkingRecordInfoVOIPage.getRecords();
        PageResult<ParkingRecordInfoVO> pageResult = new PageResult((Page) parkingRecordInfoVOIPage);
        return Result.success(parkingRecordInfoList, pageResult);
    }

    @GetMapping("/review/pending/count")
    @ApiOperation(value = "停车备案待审核数量",notes = "停车备案待审核数量",httpMethod = "GET")
    public Result<?> countPending(HttpServletRequest request){
        return Result.success(parkingRecordReviewService.countPending());
    }

    @GetMapping("/review/pass/count")
    @ApiOperation(value = "停车备案已通过数量",notes = "停车备案已通过数量",httpMethod = "GET")
    public Result<?> countPass(HttpServletRequest request){
        return Result.success(parkingRecordReviewService.countPass());
    }

    @GetMapping("/review/rejected/count")
    @ApiOperation(value = "停车备案已拒绝数量",notes = "停车备案已拒绝数量",httpMethod = "GET")
    public Result<?> countRejected(HttpServletRequest request){
        return Result.success(parkingRecordReviewService.countRejected());
    }
}
